package com.test.springboot3.springboot3testdemo1.controller;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 *
 * @author： liuziyang
 * @date： 2024/8/6-下午3:54
 * @description：
 * @modifiedBy：
 * @version: 1.0
 */
@RequiredArgsConstructor
@RestController
@Slf4j
public class AmqpMsgController {
  private final RabbitTemplate rabbitTemplate;

  @RequestMapping("/sendAmqp")
  public String sendMsg(@RequestParam("msg") String msg) {
    rabbitTemplate.convertAndSend("test-direct-exchange", "test-direct-routing-key", msg);
    return "success";
  }

  @RabbitListener(queues = "test-direct-queue")
  public void receiveMsg(String msg) {
    log.info("[RabbitMQ] receive msg: {}", msg);
  }
}
